package com.tnl.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StrUtils {

	public static boolean isEmpty(String phone) {
		if(phone==null||phone.length()<1){
			return true;
		}
		phone=phone.trim();
		if(phone.length()<1){
			return true;
		}
		return false;
	}
	
	/**
	 * 保护用户隐私-姓名
	 * @param str
	 * @return
	 */
    public static String replaceNameX(String str){
    	String custName = str;
    	int length = custName.length();
    	
    	String reg = ".{1}";
    	StringBuffer sb = new StringBuffer();
    	Pattern p = Pattern.compile(reg);
    	Matcher m = p.matcher(str);
    	int i = 0;
    	while(m.find()){
    		i++;
    		if(i==1) {
    			continue;
    		}
    		m.appendReplacement(sb, "*");
    	}
    	m.appendTail(sb);
    	return sb.toString();
   }
    
    /**
               * 保护用户隐私-电话
     * @param str
     * @return
     */
    public static String replacePhone(String str) {
    	String hidenPhone = str.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
    	return hidenPhone;
    }

}
